const bizAppEnUS = {};
const bizAppZhCN = {};

bizAppZhCN.Currency = '￥';
bizAppEnUS.Currency = '$';
bizAppZhCN.Edit = '编辑';
bizAppEnUS.Edit = 'Edit';
bizAppZhCN.FieldValidateInfo = '表单校验信息';
bizAppEnUS.FieldValidateInfo = 'Field Validate Info';
bizAppZhCN.CantBeNull = '不能为空';
bizAppEnUS.CantBeNull = 'Cant Be Null';
bizAppZhCN.Operate = '操作';
bizAppEnUS.Operate = 'Action';
bizAppZhCN.View = '查看';
bizAppEnUS.View = 'View';
bizAppZhCN.Search = '查询';
bizAppEnUS.Search = 'Search';
bizAppZhCN.City = '城市';
bizAppEnUS.City = 'City';
bizAppZhCN.Process = '处理';
bizAppEnUS.Process = 'Process';
bizAppZhCN.CreateNew = '创建新的支付';
bizAppEnUS.CreateNew = 'Create New ';
bizAppZhCN.Discard = '放弃';
bizAppEnUS.Discard = 'Discard';
bizAppZhCN.No = '否';
bizAppEnUS.No = 'No';
bizAppZhCN.Attachment = '附件';
bizAppEnUS.Attachment = 'Attachment';
bizAppZhCN.ServiceNotRegistered = '该服务没有注册';
bizAppEnUS.ServiceNotRegistered = 'Service Not Registered';
bizAppZhCN.Update = '更新';
bizAppEnUS.Update = 'Update';
bizAppZhCN.UpdateAndContinue = '更新并装载下一个';
bizAppEnUS.UpdateAndContinue = 'Update And Continue';
bizAppZhCN.Associate = '关联';
bizAppEnUS.Associate = 'Associate';
bizAppZhCN.Manage = '管理';
bizAppEnUS.Manage = 'View';
bizAppZhCN.Merge = '合并';
bizAppEnUS.Merge = 'Merge';
bizAppZhCN.Home = '回到主页';
bizAppEnUS.Home = 'Home';
bizAppZhCN.BasicInfo = '基础信息';
bizAppEnUS.BasicInfo = 'Basic Info';
bizAppZhCN.Getacustomsample = '就可以得到定制的例子';
bizAppEnUS.Getacustomsample = 'Get a custom sample';
bizAppZhCN.Empty = '空';
bizAppEnUS.Empty = 'Empty';
bizAppZhCN.List = '列表';
bizAppEnUS.List = 'List';
bizAppZhCN.ListSuffix = '列表';
bizAppEnUS.ListSuffix = '+List';
bizAppZhCN.Skip = '略过';
bizAppEnUS.Skip = 'Skip';
bizAppZhCN.ServiceNameNotProvided = '没有提供后台服务的名字';
bizAppEnUS.ServiceNameNotProvided = 'Service Name Not Provided';
bizAppZhCN.BatchUpdate = '批量更新';
bizAppEnUS.BatchUpdate = 'Batch Update';
bizAppZhCN.BatchDelete = '批量删除';
bizAppEnUS.BatchDelete = 'Batch Delete';
bizAppZhCN.MoveTo = '迁移到其他';
bizAppEnUS.MoveTo = 'Move To';
bizAppZhCN.ClearCriteria = '清除搜索条件';
bizAppEnUS.ClearCriteria = 'Clear Criteria';
bizAppZhCN.Collapse = '收起';
bizAppEnUS.Collapse = 'Collapse';
bizAppZhCN.Clear = '清空';
bizAppEnUS.Clear = 'Clear';
bizAppZhCN.PleaseInput = '请输入';
bizAppEnUS.PleaseInput = 'Please Input ';
bizAppZhCN.PleaseInput = '请输入请输入';
bizAppEnUS.PleaseInput = 'Please Input ';
bizAppZhCN.PleaseSearch = '请搜索';
bizAppEnUS.PleaseSearch = 'Please Search ';
bizAppZhCN.PleaseSelectNew = '请选择新的';
bizAppEnUS.PleaseSelectNew = 'Please Select New';
bizAppZhCN.PleaseSelectItemtoProceed = '请选择要操作的项来执行更多功能';
bizAppEnUS.PleaseSelectItemtoProceed = 'Please Select Item to Proceed';
bizAppZhCN.Cancel = '取消';
bizAppEnUS.Cancel = 'Cancel';
bizAppZhCN.NoTargetItems = '缺少被更新的对象';
bizAppEnUS.NoTargetItems = 'No Target Items';
bizAppZhCN.ScanQRCodetoUploadfromSmartPhone = '扫描二维码可以从手机上传图片或者附件';
bizAppEnUS.ScanQRCodetoUploadfromSmartPhone = 'Scan QR Code to Upload from Smart Phone';
bizAppZhCN.Preference = '设置';
bizAppEnUS.Preference = 'Preference';
bizAppZhCN.Setting = '设置';
bizAppEnUS.Setting = 'Preference';
bizAppZhCN.Profile = '基础数据';
bizAppEnUS.Profile = 'Profile';
bizAppZhCN.Permission = '权限配置';
bizAppEnUS.Permission = 'Permission';
bizAppZhCN.Yes = '是';
bizAppEnUS.Yes = 'Yes';
bizAppZhCN.Submit = '提交';
bizAppEnUS.Submit = 'Submit';
bizAppZhCN.SubmitAndContinue = '提交并建下一个';
bizAppEnUS.SubmitAndContinue = 'Submit And Continue';
bizAppZhCN.ImageList = '图片列表';
bizAppEnUS.ImageList = 'Image List';
bizAppZhCN.Exit = '退出';
bizAppEnUS.Exit = 'Exit';
bizAppZhCN.NotAssigned = '未分配';
bizAppEnUS.NotAssigned = 'Not Assigned';
bizAppZhCN.EveryPartCanBeCustomed = '下面各个渲染方法都可以定制，只要在每个模型的里面的';
bizAppEnUS.EveryPartCanBeCustomed = 'Every Part Can Be Customed';
bizAppZhCN.CloseToShowAll = '下面显示最近更新结果，关闭显示全部';
bizAppEnUS.CloseToShowAll = 'Close to Show All';
bizAppZhCN.Items = '项';
bizAppEnUS.Items = 'Items';
bizAppZhCN.New = '新建';
bizAppEnUS.New = 'New';
bizAppZhCN.CreateNew = '新建一个';
bizAppEnUS.CreateNew = 'Create New';
bizAppZhCN.Add = '新增';
bizAppEnUS.Add = 'Add';
bizAppZhCN.Totally = '一共';
bizAppEnUS.Totally = 'Totally';
bizAppZhCN.Dashboard = '仪表板';
bizAppEnUS.Dashboard = 'Dashboard';
bizAppZhCN.Selected = '已选择';
bizAppEnUS.Selected = 'Selected';
bizAppZhCN.NotAssigned = '暂无';
bizAppEnUS.NotAssigned = 'Not Assigned';
bizAppZhCN.Expand = '展开';
bizAppEnUS.Expand = 'Expand';
bizAppZhCN.Success = '执行成功';
bizAppEnUS.Success = 'Success';
bizAppZhCN.Reassign = '重新分配';
bizAppEnUS.Reassign = 'Reassign';
bizAppZhCN.Reset = '重置';
bizAppEnUS.Reset = 'Reset';
bizAppZhCN.Switchers = '状态集合';
bizAppEnUS.Switchers = 'Switchers';
bizAppZhCN.Chars = '字';
bizAppEnUS.Chars = 'Chars';
bizAppZhCN.MaxLength = '最大长度是';
bizAppEnUS.MaxLength = 'Max Length';
bizAppZhCN.MinLength = '最小长度';
bizAppEnUS.MinLength = 'Min Length';

bizAppZhCN.YesOrNo = '是否';
bizAppEnUS.YesOrNo = 'Yes/No';

const oneOf = (value, candidates) => {
  return candidates.filter(item => item == value).length > 0;
};

const isLegalLocale = value => {
  return oneOf(value, ['enUS', 'zhCN']);
};

const determinLocale = userContext => {
  const defaultLocale = 'zhCN';
  if (userContext == null) {
    const userLang = navigator.language || navigator.userLanguage;
    const trimedLocale = userLang.replace('-', '');
    if (isLegalLocale(trimedLocale)) {
      return defaultLocale;
    }
    return defaultLocale;
  }
  
  const userLocale = userContext.userLocale;
  if (isLegalLocale(userLocale)) {
    return userLocale;
  }

  return defaultLocale;
};

const internalLocaleName = (key, locale) => {
  if (locale == 'enUS') {
    return bizAppEnUS[key];
  }
  if (locale == 'zhCN') {
    return bizAppZhCN[key];
  }
  return null;
};

const localeName = (key, locale) => {
  const value = internalLocaleName(key, locale);
  if (value == null) {
    return key + 'NeedToFix';
  }
  return value;
};

const defaultLocaleName = (userContext, key) => {
  const locale = determinLocale(userContext);
  return localeName(key, locale);
};

export default defaultLocaleName;
